# -*-coding:utf-8-*-

# 嵌套列表求和及遍历
def sum_list(lists):
    total = 0
    traversal = []
    for x in lists:
        if not isinstance(x, list):
            total += x
            traversal.append(x)
        else:
            c = sum_list(x)
            total += c[0]
            traversal += c[1]
    return total, traversal


l = [[1, 2, 3], 1, 3, [1, [1, 2]]]
print(sum_list(l))


# 求第n个斐波那契数
def foo(n):
    if n == 1 or n == 2:
        return 1
    return foo(n-1) + foo(n-2)
